package nl.jworks.epub.organizer.itest.listallbooks;

import org.jbehave.core.InjectableEmbedder;
import org.jbehave.core.annotations.Configure;
import org.jbehave.core.annotations.UsingEmbedder;
import org.jbehave.core.annotations.spring.UsingSpring;
import org.jbehave.core.configuration.MostUsefulConfiguration;
import org.jbehave.core.embedder.Embedder;
import org.jbehave.core.failures.FailingUponPendingStep;
import org.jbehave.core.io.CodeLocations;
import org.jbehave.core.io.StoryFinder;
import org.jbehave.core.junit.spring.SpringAnnotatedEmbedderRunner;
import org.junit.Test;
import org.junit.runner.RunWith;

import java.net.URL;
import java.util.Arrays;
import java.util.List;

@RunWith(SpringAnnotatedEmbedderRunner.class)
@Configure(pendingStepStrategy = FailingUponPendingStep.class)
@UsingEmbedder(embedder = Embedder.class, verboseFiltering = true)
@UsingSpring(resources = {
        "spring/configuration.xml",
        "spring/steps.xml"
} )
public class ListAllBooksStory extends InjectableEmbedder {

    @Test
    public void run() {
        injectedEmbedder().runStoriesAsPaths(storyPaths());
    }

    protected List<String> storyPaths() {
        URL url = CodeLocations.codeLocationFromPath("src/test/resources");

        System.out.println("url " + url);
        String searchInDirectory = url.getFile();
        List<String> paths = new StoryFinder().findPaths(searchInDirectory, Arrays.asList("**/*.story"), null);

        System.out.println("paths: "+ paths);

        return paths;
    }
}